package com.kang.controller;

import com.kang.entity.Folder;
import com.kang.service.FolderService;
import com.kang.util.WebResponse;
import com.kang.vo.FolderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "文件夹接口")
@RestController
@RequestMapping("/admin/folder")
@Slf4j
public class FolderController {

    @Autowired
    private FolderService folderService;

    @ApiOperation("添加文件夹")
    @PostMapping("insertFolder")
    public WebResponse insertFolder(@RequestBody Folder folder) {
        try {
            return WebResponse.resSuccess("添加文件夹成功",folderService.insertFolder(folder));
        } catch (Exception ex) {
            log.error("添加文件夹失败",ex);
            return WebResponse.resFail("添加文件夹失败",null);
        }
    }

    @ApiOperation("删除文件夹")
    @PostMapping("deleteFolder")
    public WebResponse deleteFolder(@RequestBody Folder folder) {
        try {
            return WebResponse.resSuccess("删除文件夹成功",folderService.deleteFolder(folder));
        } catch (Exception ex) {
            log.error("删除文件夹失败",ex);
            return WebResponse.resFail("删除文件夹失败",null);
        }
    }

    @ApiOperation("分页查询文件夹")
    @GetMapping("getFolderPage")
    public WebResponse getFolderPage(FolderVo vo) {
        try {
            return WebResponse.resSuccess("分页查询文件夹成功",folderService.getFolderPage(vo));
        } catch (Exception ex) {
            log.error("分页查询文件夹失败",ex);
            return WebResponse.resFail("分页查询文件夹失败",null);
        }
    }

    @ApiOperation("修改状态")
    @PostMapping("updateIsShow")
    public WebResponse updateIsShow(@RequestBody FolderVo vo) {
        try {
            return WebResponse.resSuccess("修改状态成功",folderService.updateIsShow(vo));
        } catch (Exception ex) {
            log.error("修改状态失败",ex);
            return WebResponse.resFail("修改状态失败",null);
        }
    }

    @ApiOperation("用户端展示")
    @GetMapping("getFolderShow")
    public WebResponse getFolderShow() {
        try {
            return WebResponse.resSuccess("用户端展示成功",folderService.getFolderShow());
        } catch (Exception ex) {
            log.error("用户端展示失败",ex);
            return WebResponse.resFail("用户端展示失败",null);
        }
    }



}
